﻿<?php
require("../../../config/connect.php");
require("../../../public/common.php");
require("../../../public/sendphone.php");


$msg_index = trim(CheckUrlParamNoDie("msg"))-1;
$phone = trim(CheckUrlParamNoDie("phone"));
$name = urldecode(trim(CheckUrlParamNoDie("name")));

if ($phone == "")
{
	echo "-5";
	exit;
}

$msgs = array(
	"希望这是你收到的第一条祝福，比我早的统统和谐掉；煽情的话放在心里，要低调；我发的不是短信，是祝福",
	"你愿或不愿意，兔年都已过去。你想或不想经历，新的龙年都已到来。你信或不信，我们的生活都将会越来越好！",
	"往日金戈铁马，今日英姿勃发，踏平坎坷羁绊，一路朝歌彩霞；新年亲人牵挂，祝愿事业腾达，富贵共享海角天涯",
	"祝福加祝福是很多个祝福，祝福减祝福是祝福起点，祝福乘祝福是无限个祝福，祝福除祝福是唯一的祝福，祝福你",
	"送你一件外套，前面是平安，后面是幸福，吉祥是领子，如意是袖子，快乐是扣子，穿上吧，让它与你相伴每一天",
	"声声祝福，丝丝情谊，串串思念，化作一份礼物，留在你的心田，祝新年快乐，万事如意！",
	"新年到，愿君:百事可乐！万事芬达！天天娃哈哈！月月乐百事！年年高乐高！心情似雪碧！永远都醒目！",
	"酒越久越醇，水越流越清，世间沧桑越流越淡，朋友情谊越久越真。衷心祝福吾友度过一个祥和美满的新年！",
	
	"新年到，吃大餐；少喝酒，多吃菜；够不着，站起来；有人敬，耍耍赖；吃不了，兜回来！",
	"不许动！举起手来，还在笑，说你呢！快放下手机，双手抱头靠墙站好，仔细给我听着：祝你新春快乐！",
	"先申明：未经许可，不得对该祝福进行打折消费。一经发现，本人将强行不间断祝福，直到你完全想有该祝福为止",
	"￥￥￥￥￥￥￥￥￥￥当你收到这些钱的符号时，就表示你已接到财神的祝福，这将预示着你今年一定会发大财！",
	"2012来了，送你一张诺亚方舟的船票，票号是：88888888,请对号入座，开往幸福健康站！中途不得下车",
	"朋友是天，朋友是地，有了朋友可以顶天立地。朋友是风，朋友是雨，有了朋友可以呼风唤雨，祝新年快乐！",
	"祝你新的一年里大红大紫，大吉大利，这是我给你的大大礼物，你就给我回个小红包吧，支票你来签，数字我来写",
	"清蒸鱼，糖醋鱼，水煮鱼…鱼乐无穷，如鱼得水，鱼目混珠，尔鱼我炸，鱼无伦次，祝你新年快乐年年有余！");
 
$msg = $msgs[$msg_index];
if ($msg == "")
{
	echo "-4";
	exit;
}
$msg = $name. "通过购物兔给您祝福：".$msg;
function get_client_ip()
{  
    global  $_SERVER;  
    if  (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {  
        $realip  =  $_SERVER["HTTP_X_FORWARDED_FOR"];  
    } elseif  (isset($_SERVER["HTTP_CLIENT_IP"])) {  
        $realip  =  $_SERVER["HTTP_CLIENT_IP"];  
    } else {  
        $realip  =  $_SERVER["REMOTE_ADDR"];  
    }  
    return  $realip;              
}
function create_guid() {
	$charid = strtoupper(md5(uniqid(mt_rand(), true)));
	$hyphen = chr(45);// "-"
	$uuid = chr(123)// "{"
	.substr($charid, 0, 8).$hyphen
	.substr($charid, 8, 4).$hyphen
	.substr($charid,12, 4).$hyphen
	.substr($charid,16, 4).$hyphen
	.substr($charid,20,12)
	.chr(125);// "}"
	return $uuid;
}

$ip = get_client_ip();
$client_id = isset($_COOKIE["tmp_zhufu_client_id"]) ? $_COOKIE["tmp_zhufu_client_id"] : "";

if ( $client_id == "" )
{
	$client_id = create_guid();
	setcookie("tmp_zhufu_client_id", $client_id,time()+100*3600*24, "/",".gouwutu.com");
}

if(sql_getCount("tmp_zhufu", "name='$name'") >= 60)
{
	echo "-1";
	exit;
}
else if(sql_getCount("tmp_zhufu", "ip='$ip'") >= 120)
{
	echo "-2";
	exit;
}

//echo $name.'*******';
// 可以发送
//echo $phone.'*******';
$pho = explode(',', $phone);
foreach($pho as $val)
{
	//echo $val.'<br>';
	$sql = "insert into tmp_zhufu (name,phone,client_id, ip, msg) values ('$name','$val','$client_id', '$ip', '$msg')";
	//echo $sql;
	$result = mysql_query( $sql );
	if( $result )
	{
		SendPhone($val, $msg);
	}
	else 
	{
		echo "-3";
	}
}

echo "0";

?>